--Api 表
/*
select * from SYS_Apis
select * from SYS_ApiM --M  Memo Main Manage
ReturnType
返回类型（类似返回值）
1 execSql 
2 openSql
3 execProc(不带返回结果) 
4 openProc(带返回结果集)
5 getList (使用getList sql 模板)
6 执行updata,delete 等，返回 操作的行数
*/

declare 
  @ApiName varchar(50)='sjdg.editFolder',
  @ReturnType int =6
--
--
delete from SYS_Apis where apiName=@ApiName
delete from SYS_ApiM where apiName=@ApiName
insert into SYS_ApiM
  ([apiName],[Name],Memo)
select @ApiName,'底稿引用关系增加文件夹','增加底稿引用关系，底稿平台抽屉添加文件夹用了'
insert into SYS_Apis(ApiName,paramsLen,params,ReturnType,sqlText)
select @ApiName,0,
'',
@ReturnType,
'if exists(select 1 from [#(dbname)]..dglinkinfo where linkType=0 and dgid=#para(dgid) and linkDgid=#para(folderName)
#if(folderID) and linkID<>#para(folderID)#end
)
begin
  RAISERROR(''文件夹名 %s 已存在'',16,1,#para(folderName))
  return
end
#if(folderID)
  update [#(dbname)]..dglinkinfo set linkDgid=#para(folderName),updateTime=getdate() where linkID=#para(folderID)
#else
insert into [#(dbname)]..dglinkinfo(LinkID,dgid,linkType,linkdgid,adduser,adddate,updateTime,PLinkID)
values(newid(),#para(dgid),0,#para(folderName),#para(username),getdate(),getdate(),#para(parentID))
#end
' 